package com.lyhengtongwl.zqsnews.widget;

import android.app.Activity;
import android.content.Intent;
import android.os.CountDownTimer;
import android.widget.TextView;

import com.lyhengtongwl.zqsnews.ui.activity.MainActivity;

public class AdTimer extends CountDownTimer {

    /**
     * @Fields count : 倒计时
     */
    private static int count = 4 * 1000;
    private static int countDownInterval = 1000;

    private Activity mAct;
    private TextView tvAdtime;

    public AdTimer(Activity act, TextView textView) {
        super(count, countDownInterval);
        this.mAct = act;
        this.tvAdtime = textView;
    }


    /**
     * 倒计时过程中调用
     *
     * @param millisUntilFinished
     */
    @Override
    public void onTick(long millisUntilFinished) {
        String leftTime = millisUntilFinished / 1000 + "秒";
        this.tvAdtime.setText(leftTime);
    }


    /**
     * 倒计时完成后调用
     */
    @Override
    public void onFinish() {
        mAct.startActivity(new Intent(mAct, MainActivity.class));
        mAct.finish();
    }
}
